<?php
#基础函数
include_once('_path.php');

if (BENCHMARK) {
	require_once(_CONST_LOCAL_INCLUDE_PATH.'/Benchmark/Timer.php');
	$timer = new Benchmark_Timer();
	$timer->start();
}

#db
include_once(_CONST_LOCAL_INCLUDE_PATH."database.class.php");
$database = new Database($db_vars);

if ($db_slave_vars['hostname'] != '') {
	$slave = new Database($db_slave_vars);
} else {
	$slave =& $database;
}

#通用函数
include_once(_CONST_LOCAL_INCLUDE_PATH."common.php");

if (BENCHMARK) $timer->setMarker('init');

#登录权限
check_loggedin();

#用户信息
include_once(_CONST_LOCAL_INCLUDE_PATH."session.include.php");

if (BENCHMARK) $timer->setMarker('auth');

#处理上一步骤
$token = $_POST['token'];
if(empty($token) || $token != $_SESSION['token']){
		//exit("Access Exit!");
		header("Location:"._CONST_WEB_URL."flow-1.php");
		exit;
}
#校验
verify_field("desc", "Description", "empty");
verify_field("desc", "Description", "minlength", 10);
verify_field("desc", "Description", "maxlength", 140);
if (count($error_strs)) {
	exit("Error Pargram Exit!");
}

$desc = trim($_POST['desc']);

$_SESSION['step_3'] = array(
	'desc' => $desc,
);

#初始化第二步
$token = md5(uniqid().time());
$_SESSION['token'] = $token;

#处理缩略图
include_once(_CONST_LOCAL_INCLUDE_PATH.'phpthumb/ThumbLib.inc.php');

function resizeImg($imgfile, $type)
{	
	$myfile = md5($imgfile) . '.jpg';
	if(!file_exists(_CONST_UPLOAD_PATH.$myfile)){
		#删除之前的图片
		if(isset($_SESSION['step_4'][$type])){
			@unlink(_CONST_UPLOAD_PATH . $_SESSION['step_4'][$type]);
		}
		$options = array('resizeUp' => true, 'jpegQuality' => 100);
		$thumb = PhpThumbFactory::create($imgfile, $options);
		$thumb->adaptiveResize(450, 450);
		$thumb->save(_CONST_UPLOAD_PATH.$myfile);
		$_SESSION['step_4'][$type] = $myfile;
	}
	return $myfile;
}

$mytitle = $_SESSION['step_1']['title'];
$mydesc = $_SESSION['step_3']['desc'];

#cache lite
include_once(_CONST_LOCAL_INCLUDE_PATH.'Cache/Lite.php');
include_once(_CONST_LOCAL_INCLUDE_PATH.'Cache/Lite/Output.php');

$cache = new Cache_Lite_Output();

#用于meta的keywords标签
$keywords = "";
#用于meta的Description标签
$description = "";
#用于mete的http-equiv标签
$referrer = "";
#用于meta的title标签
$title = "发布投票 - Votings";
#用于获取针对本页的css样式
$css = array();
#用于获取针对本页的js
$js = array();
#用于获取针对head的其他标签
$links = array();
#用于控制那个主菜单为
$o = "";

$ads = array();

$post_code =<<<HTML
HTML;

if (BENCHMARK) $timer->setMarker('proc');

//if ($user['loggedin'] < 1)
//	cache_header(900);

no_cache_header();

#header
include_once(_CONST_LOCAL_LAYOUT_PATH."_header.php");
?>
<div id="main">
<form name="step4" id="step-4" action="finish.php" method="post">
<input name="token" id="token" type="hidden" value="<?php echo $token;?>">
	<div class="box">
		<ul class="flow clearfix f4">
			<li>1、选择商品图片</li>
			<li>2、选择自己的照片</li>
			<li>3、添加一段描述</li>
			<li class="cur">4、发布投票</li>
		</ul>
		<div class="box-header"><h1>投票预览</h1></div>
		
		<div class="voting-header">
			<h1><?php echo htmlspecialchars($mytitle)?></h1>
			<div class="votings-data"><span class="votings-down">0</span><span class="votings-up">0</span><span class="votings-views">0</span></div>
		</div>
		<div class="voting-body voting-preview">
			<div class="voting-pics">
				<div class="user-pic"><img src="<?php echo _CONST_UPLOAD_URL . resizeImg($_SESSION['step_2']['myimg'], 1);?>" alt="name" /></div>
				<div class="product-pic"><img src="<?php echo _CONST_UPLOAD_URL . resizeImg($_SESSION['step_1']['gimg'], 2);?>" alt="product name" /></div>
				<div class="voting-link"><img src="<?php echo _CONST_IMG_URL?>bg/voting-link.png" alt="voting" /></div>
			</div>
			<div class="voting-more clearfix">
				<blockquote class="voting-des"><?php echo htmlspecialchars($mydesc)?></blockquote>
			</div>
		</div>
		<div class="next-step"><input type="button" name="previous-step" class="previous" value="" onclick = "window.location.href='<?php echo _CONST_WEB_URL . 'flow-3.php'?>';" /><input type="button" name="voting-publish" class="voting-publish" value="" onclick="vote.checkForm4();" /></div>
	</div>
</form>	
</div>
<!--main end-->
<?php
//footer
include_once (_CONST_LOCAL_LAYOUT_PATH."_footer.php");

if (BENCHMARK) $timer->setMarker('page');

if (BENCHMARK) {
	echo "<!-- init: ".$timer->timeElapsed('Start', 'init')." -->\n";
	echo "<!-- auth: ".$timer->timeElapsed('init', 'auth')." -->\n";
	echo "<!-- proc: ".$timer->timeElapsed('auth', 'proc')." -->\n";
	echo "<!-- page: ".$timer->timeElapsed('proc', 'page')." -->\n";
	echo "<!-- total: ".$timer->timeElapsed('Start', 'Stop')." -->\n";
}

?>
